<!--录用审核-->
<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="hearder-search">
        <div class="breadcrumb-container">
          <el-input v-model="searchForm.name" placeholder="姓名" @keyup.enter.native="searchBtn" size="small"
                    class="w-140 mr-10"></el-input>
          <el-select v-model="searchForm.job_id" placeholder="选择岗位" size="small">
            <el-option
                v-for="item in jobList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
          <el-button type="primary" size="small" @click="searchFn('search')" class="ml-10"><i
              class="el-icon-search"></i>搜索
          </el-button>
          <el-button size="small" @click="searchFn('refresh')"><i class="el-icon-refresh"></i>重置刷新</el-button>
        </div>
      </div>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane :label="`待处理审核（${numberList[0]}）`" name="first"></el-tab-pane>
        <el-tab-pane :label="`历史审核（${numberList[1]}）`" name="history"></el-tab-pane>
      </el-tabs>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :border="tableoption.tableBorder"
              tooltip-effect="dark">
            <el-table-column
                label="应聘岗位"
                align="center"
                prop="name"
                :key="1">
              <template slot-scope="scope">
                {{ scope.row.recruit.job.name }}
              </template>
            </el-table-column>
            <el-table-column
                label="应聘人"
                align="center"
                prop="name"
                :key="2">
            </el-table-column>
            <el-table-column
                label="个人近照"
                align="center"
                prop="use_time"
                :key="4">
              <template slot-scope="scope">
<!--                <viewerModle type="1" :imgSrc="scope.row.pic"></viewerModle>-->
                <ImagePreview :src="scope.row.pic" width="40px" height="40px"></ImagePreview>
              </template>
            </el-table-column>
            <el-table-column
                label="电话"
                align="center"
                prop="mobile_phone"
                :key="3">
            </el-table-column>
            <el-table-column
                label="性别"
                align="center"
                :key="5"
                width="60">
              <template slot-scope="scope">
                {{ scope.row.sex == 1 ? '男' : '女' }}
              </template>
            </el-table-column>
            <el-table-column
                label="年龄"
                align="center"
                prop="age"
                width="60"
                :key="6">
            </el-table-column>
            <el-table-column
                label="学历"
                align="center"
                :key="7">
              <template slot-scope="scope">
                {{ scope.row.edu.name }}
              </template>
            </el-table-column>
            <el-table-column
                label="投递时间"
                align="center"
                prop="create_time"
                :key="8">
            </el-table-column>
            <el-table-column
                label="面试时间"
                align="center"
                prop="recruit_time"
                :key="9">
            </el-table-column>
            <el-table-column
                label="状态"
                align="center"
                prop="status"
                :key="12">
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                :width="activeName=='first'?240:140"
                :key="13">
              <template slot-scope="scope">
                <el-button size="small" @click="showDetail(scope.row.id)">查看简历详情</el-button>
                <el-button size="small" @click="showResumeDetail(scope.row.id)" v-if="activeName=='first'">录用审核</el-button>
                <el-button type="danger" size="small" @click="detelFn(scope.row.id)" plain v-if="userInfo.id==1">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
      </el-col>
    </div>
    <!--    简历详情-->
    <resumeDetail :visible.sync="resumeVisible" :resumeId="resumeId"></resumeDetail>
    <!--    考核项-->
    <AssessmentItems :visible.sync="AssessmentItemsVisible" :resumeId="resumeId" @InitFn="InitFn" :resumeType="activeName=='first'?'edit':'show'" ></AssessmentItems>
  </div>
</template>

<script>
import {pagination, tableoption, yeartime} from '@/utils/util.js'
import resumeDetail from "./resumeDetail";
import AssessmentItems from "./AssessmentItems";
import {personnelDelete} from "@/api/admin/personnel";
import {mapGetters} from "vuex";

export default {
  components: {
    resumeDetail,
    AssessmentItems
  },
  data() {
    return {
      tableoption: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      // 弹窗
      resumeVisible: false,
      resumeId: 0,
      jobList: [],
      searchForm: {
        job_id: '',
        name: ''
      },
      AssessmentItemsVisible: false,
      activeName: 'first',
      activeNamechange: 'first',
      numberList: [0, 0]
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  created() {
    this.InitFn()
    this.JobFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      // <!--        resumeType 1 查看简历 2 待处理的简历 3 待面试简历 4 考核中的应聘者 5 一录用应聘者-->
      // p 	整型 	必填 	1 	- 	页码
      // rercuit_sn 	字符串 	必填 	1 	- 	招聘发布编号
      // title 	字符串 	必填 	1 	- 	招聘名称
      // name 	字符串 	必填 	1 	- 	面试人
      // mobile_phone 	字符串 	必填 	1 	- 	面试人电话
      // status 	字符串 	必填 	1 	- 	0待审核1通过2驳回
      // recruit_id
      // statuss 0 简历待审核 1 待面试 2 简历驳回不符合 3 面试淘汰 4 考核中 5 录用 6 考核不通过 7 离职中 8 离职通过 9 离职驳回
      // 0 简历待处理 1 历史审核记录 2 面试待处理 3 面试历史 4 录用待处理 5 录用历史
      let option = {
        p: this.page.pageindex,
        status: 4,
        type: this.activeName === 'first' ? 4 : 5,
        name: this.searchForm.name,
        job_id: this.searchForm.job_id,
      };

      let data = await this.$fetch(this.api.recruit.vitae.index, option);
      if (!data.code) {
        for (let i in data.list.data) {
          data.list.data[i].create_time = data.list.data[i].create_time.split(' ')[0]
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
        this.numberList = this.getJson(data.number)
      }
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 搜索
    searchBtn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    // 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.searchCatId = ''
      this.searchCatId = 0
      this.InitFn()
    },
    showDetail(id) {
      this.resumeId = id
      this.resumeVisible = true
    },
    // 获取岗位信息
    async JobFn() {
      let data = await this.$fetch(this.api.recruit.job.index, {p: 1});
      this.jobList = data.list.data;
    },
    showResumeDetail(id) {
      this.resumeId = id
      this.AssessmentItemsVisible = true
    },
    handleClick(tab, event) {
      if (this.activeName !== this.activeNamechange) {
        this.activeNamechange = this.activeName;
        this.page.pageindex = 1
        this.arryList = []
        this.InitFn()
      }
    },
    searchFn(option) {
      if (option === 'refresh') {
        this.searchForm.name = ''
        this.searchForm.job_id = ''
      }
      this.page.pageindex = 1;
      this.InitFn()
    },
    detelFn(id) {
      let self_ = this
      this.$confirm('确认删除该录用信息，确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        personnelDelete({id: id}).then(res => {
          if(!res.code){
            this.$message.success('删除成功！')
            self_.InitFn()
          }
        })
      }).catch(() => {

      })
    }
  },
  mounted() {
  }
}
</script>
